/* BELOM SELESAI */

int HariKeN(MemberList *L,string InfoBday) {
	
}

address CariAddress (MemberList L, string CurrentUser) 
// menghasilkan address dari CurrentUser (CurrentUser berisi email dari current user)
{
	P = First(L);
	while (P!=Nil) {
		if (InfoEmail(P) == CurrentUser) { //STRCMP
			return P;
		}
		P = Next(P);
	}
}

void FirstFriend (MemberList *L, string CurrentUser, FriendList *F1)
// F.S 1st friend dari CurrentUser dimasukkan ke variabel F
{
	Uaddress P;
	CreateFriendList(F);
	P = First(*L);
	while (InfoEmail(P) != CurrentUser) {
		P = Next(P);
	}
	//kondisi : InfoEmail(P) == CurrentUser
	(*F) = P.Friends;
}

void SecondFriend (MemberList *L, string CurrentUser, FriendList *F2) {
	Faddress P,R,P1;
	CreateFriendList(*F2);
	FriendList F1;
	FirstFriend(L,CurrentUser,F1);
	// kondisi : F1 berisi 1st friend dari CurrentUser
	P = First(F1);
	while (P!=Nil) {
		FirstFriend(L,InfoEmail(P),P1);
		//P1 berisi 1st friend dari P
		R = First(P1)
		while (R!=Nil) {
			if (! IsFound(L,InfoEmail(R),F1)) {
				F2 = R;
				Next(F2) = Nil;
				F2 = Next(F2);
			}
			R= Next(R);
		}
		P = Next(P);	
	}
}

void ThirdFriend (MemberList *L, string CurrentUser, FriendList *F3) {
	Faddress P,R,P1;
	CreateFriendList(*F3);
	FriendList F1,F2;
	FirstFriend(L,CurrentUser,F1);
	SecondFriend(L,CurrentUser,F2);
	P = First(F2);
	while (P!=Nil) {
		FirstFriend(L,InfoEmail(P),P1);
		R = First(P1);
		while (R!=Nil) {
			if (! IsFound (L,InfoEmail(R),F1)) {
				F3 = R;
				Next(F3) = Nil;
				F3 = Next(F3);
			}
			R = Next(R);
		}
		P = Next(P);
	}
}

void Birthday (MemberList *L, string CurrentUser, int day, int today) {
	//bila day tidak ada, default 7 hari. gimana caranya bikin day sbg opsional?
	FriendList F1;
	FirstFriend(L,CurrentUser,F1);
	Faddress P1;
	int Hari;
	P1 = First(F1);
	while (P1!=Nil) {
		Hari = HariKeN(*L,InfoTglLahir(P1));
		if ((Hari >= today) && (Hari <= (today+day))) {
			if //CurrentUser juga merupakan 1st friend dari P1
				printf("%s %s %s %s %s %s",InfoEmail(P1),InfoSMU(P1),InfoNama(P1),InfoTglLahir(P1),InfoKotaAsal(P1),InfoUniv(P1));
			}
			else {
				printf("%s %s %s XX-XX-XXXX %s %s",InfoEmail(P1),InfoSMU(P1),InfoNama(P1),InfoKotaAsal(P1),InfoUniv(P1));
			}
		}
		P1 = Next(P1);
	}		
}

void Same (MemberList *L, string CurrentUser, string state) {
	FriendList F1,F2,F3;
	string S;
	Faddress P1,P2,P3;
	FirstFriend(L,CurrentUser,F1);
	SecondFriend(L,CurrentUser,F2);
	ThirdFriend(L,CurrentUser,F3);
	P = CariAddress(CurrentUser);
	
	printf("1st Friend\n");
	P1 = First(F1);
	if (P1==Nil) {
		printf("N\A\n");
	}
	else {	
		printf("ID	Highschool	Name		Birthday		Hometown		University\n");
		while (P1!=Nil) {
			if (state="Universitas") {
				if (InfoUniv(P1) == InfoUniv(PCurrentUser)) {
				printf("%s %s %s %s %s %s",InfoEmail(P1),InfoSMU(P1),InfoNama(P1),InfoTglLahir(P1),InfoKotaAsal(P1),InfoUniv(P1));
			}  
			else 
				if (state="SMU") {
					if (InfoSMU(P1) == InfoSMU(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P1),InfoSMU(P1),InfoNama(P1),InfoTglLahir(P1),InfoKotaAsal(P1),InfoUniv(P1));
					} 
				}
				else if (state="Hometown") {
					if (InfoKotaAsal(P1) == InfoKotaAsal(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P1),InfoSMU(P1),InfoNama(P1),InfoTglLahir(P1),InfoKotaAsal(P1),InfoUniv(P1));
					} 
				}
			P1 = Next(P1);
		}
	}
	printf("\n");
	
	printf("2nd Friend\n");
	P2 = First(F2);
	if (P2==Nil) {
		printf("N\A\n");
	}
	else {
		printf("ID	Highschool	Name		Birthday		Hometown		University\n");
		while (P2!=Nil) {
			if (state="Universitas") {
				if (InfoUniv(P2) == InfoUniv(PCurrentUser)) {
				printf("%s %s %s %s %s %s",InfoEmail(P2),InfoSMU(P2),InfoNama(P2),InfoTglLahir(P2),InfoKotaAsal(P2),InfoUniv(P2));
			}  
			else 
				if (state="SMU") {
					if (InfoSMU(P2) == InfoSMU(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P2),InfoSMU(P2),InfoNama(P2),InfoTglLahir(P2),InfoKotaAsal(P2),InfoUniv(P2));
					} 
				}
				else if (state="Hometown") {
					if (InfoKotaAsal(P2) == InfoKotaAsal(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P2),InfoSMU(P2),InfoNama(P2),InfoTglLahir(P2),InfoKotaAsal(P2),InfoUniv(P2));
					} 
				}
			P2 = Next(P2);
		}
	}
	printf("\n");

	printf("3rd Friend\n");
	P3 = First(F3);
	if (P3==Nil) {
		printf("N\A\n");
	}
	else {
		printf("ID	Highschool	Name		Birthday		Hometown		University\n");
		while (P3!=Nil) {
			if (state="Universitas") {
				if (InfoUniv(P3) == InfoUniv(PCurrentUser)) {
				printf("%s %s %s %s %s %s",InfoEmail(P3),InfoSMU(P3),InfoNama(P3),InfoTglLahir(P3),InfoKotaAsal(P3),InfoUniv(P3));
			}  
			else 
				if (state="SMU") {
					if (InfoSMU(P3) == InfoSMU(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P3),InfoSMU(P3),InfoNama(P3),InfoTglLahir(P3),InfoKotaAsal(P3),InfoUniv(P3));
					} 
				}
				else if (state="Hometown") {
					if (InfoKotaAsal(P3) == InfoKotaAsal(PCurrentUser)) {
						printf("%s %s %s %s %s %s",InfoEmail(P3),InfoSMU(P3),InfoNama(P3),InfoTglLahir(P3),InfoKotaAsal(P3),InfoUniv(P3));
					} 
				}
			P3 = Next(P3);
		}
	}
	printf("\n");
}

void notfriendyet (MemberList *L, string CurrentUser) {
	FriendList F1,F2;
	Faddress P1,P2;
	FirstFriend(L,CurrentUser,F1);
	SecondFriend(L,CurrentUser,F2);
	P1 = First(F1);
	printf("2nd Friend\n");
	if (P1==Nil) {
		printf("N\A\n");
	} 
	else {
		while (P1!=Nil) {
			printf("%s %s\n",InfoEmail(P1),InfoNama(P1)); //ini ga tau nih ngeprint string nya gimana hehehe
			P1 = Next(P1);
		}
	}
	printf("\n");
	P2 = First(F2);
	printf("3rd Friend\n");
	if (P2==Nil) {
		printf("N\A\n");
	}
	else {
		while (P2!=Nil) {
			printf("%s %s\n",InfoEmail(P2),InfoNama(P2)); //ini ga tau nih ngeprint string nya gimana hehehe
			P2 = Next(P2);
		}
	}
	printf("\n");
	
}

